All right.
In this lesson, I'm going to make a wild loop where you can break the loop condition.
So I have a spinning coin.
If I run up and I touch it in any way, it's going to freeze.
I'm breaking the loop condition.
So let's go ahead and get started with that.
All right.
I'm going to use the power up coin from my last video and I'm going to put the link in the description.
This is important to learn to using other people's assets.
So I made this sharable in the marketplace.
You click on this link, you're going to get to this page.
There'll be a green get button when you press it and you open up Roblox studio.
I have a fresh world.
Go to your toolbox and under inventory you'll see the coin.
Right?
So this is Marketplace, this is inventory, this is your stuff.
Once you said get, you're going to have access to that coin.
This is the coin that I have.
With that URL.
So it says there are two scripts.
Yeah.
That's good.
Let's take a look at this.
It's a coin model.
We saved it off in the last video.
Let's move it up.
And the coin spins with the rotate, and the collect allows you to grab the coin and get powers.
Let's take a look at rotate first.
Right.
So rotate is what makes it go around, but it goes around forever.
We want to break this loop condition when we touch it, but touching it happens over in the collect
script, so we need those two to talk to each other.
Let's click on coin in the Explorer here, hit a plus and then do a B for Boolean.
So this is a boolean value.
It could be true or false and it's external to both scripts I'm going to write is rotating.
Right.
So this is going to be either true or false.
I'm going to set it to true by hitting this value button checked is true.
Unchecked is false.
Then in my rotate I'm going to say local is rotating.
Equals script to parent or what I could do since script.
Parent is the coin.
I could do coin.
You do either.
I want to find is rotating.
There we go.
That is rotating right here.
Is that boolean value right there, that object.
But in order to access the true or false, we need to have one more thing we're going to say is rotating
dot value, that value right here.
So this is going to be true because we set it to true.
Now the coin will spin just like it did before, but we can change this value external to the rotate
script.
Let's go to collect.
Let's change collect to stop coin.
Here we go.
Let's open it.
Double click on stock coin and then instead of on collect, I'm going to make this a touch event.
Right?
So I'm just going to rename the touch because I think it makes on touch.
I think it makes more sense because we're not collecting it anymore.
We're just touching it.
So I change this to On Touch.
So when we touch the coin, this is the function that'll be called right here.
And then we still want to check to see if it's a humanoid.
We're not going to do powers or destroy it, so I'll delete that.
What we are going to do is modify this is rotating.
In order to make this a little more cleaner code, I'm going to go to the top and right is rotating
get a variable for my is rotating object coin.
If I could spell it right.
There we go.
Is rotating.
This will be the variable.
Come down here, paste it, I'll say dot value equals false.
There we go.
So when we touch it, this will become false.
Go to your rotating script.
This condition is going to be broken because it's going to become false as no longer going to do the
while loop.
Let's try it out.
There we go.
We got the coin.
And it stopped.
Pretty cool.
Let's save this off too, in case we need it for later.
So.
Let's go to our.
See where the coin is right here.
Click it, right click.
And then we're going to say Pablo or save to blocks.
I'm going to overwrite the existing asset you could hit submit.
This distribute on marketplace allows you to distribute it to other people.
They can get it right.
And I had to do that so that you guys could get it.
All I want to do is I'm going to overwrite existing asset.
Coin stops when that's what it was supposed to be when touched and then submit because I already have
one, so I don't need to.
There we go.
So I will see you in the next video.
I think we should do a little bit on tables before we start moving into our game.